package org.hxzon.tapestry5.validator;

import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.validator.AbstractValidator;

public class Equal extends AbstractValidator<String, String> {
    public Equal() {
        super(String.class, String.class, "equal-string-length");
    }

    private String buildMessage(MessageFormatter formatter, Field field) {
        return formatter.format(field.getLabel());
    }

    public void render(Field field, String constraintValue, MessageFormatter formatter, MarkupWriter writer, FormSupport formSupport) {
        formSupport.addValidation(field, "equal", buildMessage(formatter, field), constraintValue);
    }

    public void validate(Field field, String constraintValue, MessageFormatter formatter, String value) throws ValidationException {
        // TODO Auto-generated method stub

    }
}
